package com.bianyuanren.web.controller.app;

import java.util.List;

import com.bianyuanren.v4.pojo.version.PpVersion;
import com.bianyuanren.v4.service.version.IPpVersionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bianyuanren.common.annotation.Log;
import com.bianyuanren.common.enums.BusinessType;
import com.bianyuanren.common.core.controller.BaseController;
import com.bianyuanren.common.core.domain.AjaxResult;
import com.bianyuanren.common.utils.poi.ExcelUtil;
import com.bianyuanren.common.core.page.TableDataInfo;

/**
 * 边缘人版本号控制Controller
 * 
 * @author bianyuanren
 * @date 2020-03-16
 */
@Controller
@RequestMapping("/app/version")
public class AppVersionController extends BaseController
{
    private String prefix = "app/version";

    @Autowired
    private IPpVersionService ppVersionService;

    @RequiresPermissions("system:version:view")
    @GetMapping()
    public String version()
    {
        return prefix + "/version";
    }

    /**
     * 查询边缘人版本号控制列表
     */
    @RequiresPermissions("system:version:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PpVersion ppVersion)
    {
        startPage();
        List<PpVersion> list = ppVersionService.selectPpVersionList(ppVersion);
        return getDataTable(list);
    }

    /**
     * 导出边缘人版本号控制列表
     */
    @RequiresPermissions("system:version:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PpVersion ppVersion)
    {
        List<PpVersion> list = ppVersionService.selectPpVersionList(ppVersion);
        ExcelUtil<PpVersion> util = new ExcelUtil<PpVersion>(PpVersion.class);
        return util.exportExcel(list, "version");
    }

    /**
     * 新增边缘人版本号控制
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存边缘人版本号控制
     */
    @RequiresPermissions("system:version:add")
    @Log(title = "边缘人版本号控制", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PpVersion ppVersion)
    {
        return toAjax(ppVersionService.insertPpVersion(ppVersion));
    }

    /**
     * 修改边缘人版本号控制
     */
    @GetMapping("/edit/{versionId}")
    public String edit(@PathVariable("versionId") Long versionId, ModelMap mmap)
    {
        PpVersion ppVersion = ppVersionService.selectPpVersionById(versionId);
        mmap.put("ppVersion", ppVersion);
        return prefix + "/edit";
    }

    /**
     * 修改保存边缘人版本号控制
     */
    @RequiresPermissions("system:version:edit")
    @Log(title = "边缘人版本号控制", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PpVersion ppVersion)
    {
        return toAjax(ppVersionService.updatePpVersion(ppVersion));
    }

    /**
     * 删除边缘人版本号控制
     */
    @RequiresPermissions("system:version:remove")
    @Log(title = "边缘人版本号控制", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ppVersionService.deletePpVersionByIds(ids));
    }
}
